package com.liu.webstore;

import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication(scanBasePackages = "com.liu.webstore.*")
//@MapperScan(basePackages = "com.liu.webstore.repository.*", annotationClass = Mapper.class)
@EnableAspectJAutoProxy(exposeProxy = true)
public class WebstoreApplication {
    public static final Logger log = LoggerFactory.getLogger(WebstoreApplication.class);

    /**
     * 管理bean的初始化方法
     */
    @PostConstruct
    public void init() {
        // 解决netty启动冲突问题
        // Netty4Utils.setAvailableProcessors()
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }


    public static void main(String[] args) throws UnknownHostException {
        SpringApplication application = new SpringApplication(WebstoreApplication.class);
        Environment env = application.run(args).getEnvironment();
        String protocol = "http";
        log.info(
                "\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\t{}://localhost:{}\n\t" +
                        "External: \t{}://{}:{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                env.getProperty("server.port"),
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port")
        );
    }

}
